package com.siyu.tickets.manager.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.siyu.common.hibernate3.Updater;
import com.siyu.common.page.Pagination;
import com.siyu.tickets.dao.ElementDao;
import com.siyu.tickets.entity.Element;
import com.siyu.tickets.manager.ElementMng;

@Service
@Transactional
public class ElementMngImpl implements ElementMng {

	@Transactional(readOnly = true)
	public Pagination getPage(String name, String type, Boolean enable, int pageNo, int pageSize) {
		Pagination page = dao.getPage(name, type, enable, pageNo, pageSize);
		return page;
	}

	@Transactional(readOnly = true)
	public List<Element> findListByType(String type) {
		return dao.findListByType(type);
	}

	@Transactional(readOnly = true)
	public Element findById(Integer id) {
		Element entity = dao.findById(id);
		return entity;
	}

	public Element save(Element bean) {
		return dao.save(bean);
	}

	public Element update(Element bean) {
		Updater<Element> updater = new Updater<Element>(bean);
		Element entity = dao.updateByUpdater(updater);
		return entity;
	}

	public Element updateByUpdater(Updater<Element> updater) {
		return dao.updateByUpdater(updater);
	}

	public Element deleteById(Integer id) {
		return dao.deleteById(id);
	}

	public Element[] deleteByIds(Integer[] ids) {
		Element[] beans = new Element[ids.length];
		for (int i = 0, len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}

	@Autowired
	private ElementDao dao;

}
